package netty.simple.heartBeat;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleStateEvent;

/**
 * @ClassName MyServerHandler
 * @Description TODO
 * @Author director吴
 * @Date 2022/4/12 13:15
 * @Version 1.0
 **/
public class MyServerHandler extends ChannelInboundHandlerAdapter  {

    /**
     *
     * @param ctx 上下文对象
     * @param evt 事件
     * @throws Exception
     */
    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        if (evt instanceof IdleStateEvent){
            IdleStateEvent event =  (IdleStateEvent)evt;
            String type = null;
            switch (event.state()){
                case READER_IDLE:
                    type = "读空闲！";
                    break;
                case WRITER_IDLE:
                    type = "写空闲！";
                    break;
                case ALL_IDLE:
                    type = "读写空闲！";
                    break;
            }
            System.out.println(ctx.channel().remoteAddress()+ "---超时事件触发:"+ type);
            System.out.println("发生["+type+"]:正在处理中...");
        }

        super.userEventTriggered(ctx, evt);
    }
}
